<template>
  <div class="science-card">
    <van-nav-bar
      title="科学探索"
      left-arrow
      @click-left="$emit('close')"
    />
    
    <div class="card-content" v-if="cardData">
      <div v-html="cardData.content"></div>
    </div>
    
    <div class="loading" v-else>
      <van-loading type="spinner" color="#6e8efb" size="24px">生成科学探索卡片中...</van-loading>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';

const props = defineProps({
  cardData: {
    type: Object,
    required: true
  }
});

defineEmits(['close']);

// 添加全局样式
const style = document.createElement('style');
style.textContent = `
  .science-card {
    min-height: 100vh;
    background-color: #f0f9ff;
    font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  }
  
  .card-content {
    padding: 16px;
    max-width: 800px;
    margin: 0 auto;
  }
  
  .card-content :deep(h1) {
    font-size: 32px;
    color: #2c3e50;
    margin-bottom: 24px;
    text-align: center;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
  }
  
  .card-content :deep(section) {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border: 2px solid #e8f4ff;
    transition: transform 0.3s ease;
  }
  
  .card-content :deep(section:hover) {
    transform: translateY(-2px);
  }
  
  .card-content :deep(section h3) {
    font-size: 22px;
    color: #4a90e2;
    margin-bottom: 16px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  
  .card-content :deep(section h3::before) {
    content: "🔬";
    font-size: 24px;
  }
  
  .card-content :deep(section.experiment h3::before) {
    content: "🧪";
  }
  
  .card-content :deep(section.fun-fact h3::before) {
    content: "💡";
  }
  
  .card-content :deep(section.think h3::before) {
    content: "🤔";
  }
  
  .card-content :deep(section p) {
    font-size: 16px;
    color: #333;
    line-height: 1.8;
    margin-bottom: 12px;
  }
  
  .card-content :deep(section ul) {
    padding-left: 24px;
    margin-bottom: 12px;
  }
  
  .card-content :deep(section li) {
    font-size: 15px;
    color: #333;
    margin-bottom: 8px;
    line-height: 1.6;
    position: relative;
  }
  
  .card-content :deep(section li::marker) {
    color: #4a90e2;
  }
  
  .card-content :deep(.safety-note) {
    background: #fff3cd;
    border: 1px solid #ffeeba;
    border-radius: 8px;
    padding: 12px;
    margin-top: 16px;
    font-size: 14px;
    color: #856404;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  
  .card-content :deep(.safety-note::before) {
    content: "⚠️";
    font-size: 20px;
  }
  
  .card-content :deep(.highlight) {
    color: #4a90e2;
    font-weight: bold;
  }
  
  .card-content :deep(.question-box) {
    background: #e8f4ff;
    border-radius: 12px;
    padding: 16px;
    margin-top: 16px;
    border: 1px dashed #4a90e2;
  }
  
  .loading {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
  }
  
  @media (max-width: 768px) {
    .card-content {
      padding: 12px;
    }
    
    .card-content :deep(h1) {
      font-size: 28px;
    }
    
    .card-content :deep(section) {
      padding: 20px;
      margin-bottom: 20px;
    }
    
    .card-content :deep(section h3) {
      font-size: 20px;
    }
    
    .card-content :deep(section p),
    .card-content :deep(section li) {
      font-size: 14px;
    }
  }
`;

onMounted(() => {
  document.head.appendChild(style);
});
</script> 